/**
 *
 */
package com.ybkj.daijia.server;


import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * @author FZH
 *
 */
public class TaskManager implements ServletContextListener {

//	private SettingUtils settingUtils; 


    @Override
    public void contextInitialized(ServletContextEvent sce) {

        WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(sce.getServletContext());
        ServletContext sc = sce.getServletContext();
        Config.setWac(context);
        Config.setWebapp(sc.getRealPath("/"));
//		settingUtils=context.getBean(SettingUtils.class);

//		try {
//			
//			JobKey dayJobKey = new JobKey("day", "dayGroupName");
//			TriggerKey dayTriggerKey = new TriggerKey("dayTrigger", "dayTriggerGroupName");
//			
//			CronTrigger trigger =  (CronTrigger) TriggerBuilder.newTrigger()
//					.withIdentity(dayTriggerKey)
//					.withSchedule(CronScheduleBuilder.cronSchedule("0 0 "+settingUtils.get().getWorkBegin()+" * * ?"))
//					.startNow()
//					.build();
//			
//			
//			JobDetail jobDetail = JobBuilder.newJob(ClearDayOrderNums.class).withIdentity(dayJobKey).build();
//			
//			
//			//JobDetail jobDetail = new JobDetail("day","dayGroupName",clearDayOrderNums.class);  
//			//CronTrigger trigger = new CronTrigger("dayTrigger","dayTriggerGroupName","0 0 "+settingUtils.get().getWorkBegin()+" * * ?");  
//	
//			Scheduler daysched= Config.getDaysched();
//			daysched = new org.quartz.impl.StdSchedulerFactory().getScheduler();  
//			daysched.scheduleJob(jobDetail,trigger);
//			daysched.start();
//			Config.setDaysched(daysched);
//			
//			//jobDetail = new JobDetail("month","monthGroupName",clearMonthOrderNums.class);  
//			//trigger = new CronTrigger("monthTrigger","monthTriggerGroupName","0 0 "+settingUtils.get().getWorkBegin()+" 1 * ? ");  
//			
//			JobKey monthJobKey = new JobKey("month","monthGroupName");
//			TriggerKey monthTriggerKey = new TriggerKey("monthTrigger", "monthTriggerGroupName");
//			
//			jobDetail = JobBuilder.newJob(ClearMonthOrderNums.class).withIdentity(monthJobKey).build();
//			
//			CronTrigger trigger2 = (CronTrigger) TriggerBuilder.newTrigger()
//					.withIdentity(monthTriggerKey)
//					.withSchedule(CronScheduleBuilder.cronSchedule("0 0 "+settingUtils.get().getWorkBegin()+" 1 * ? "))
//					.startNow()
//					.build();
//			
//			Scheduler monthsched= Config.getDaysched();
//			monthsched = new org.quartz.impl.StdSchedulerFactory().getScheduler();  
//			monthsched.scheduleJob(jobDetail,trigger2);
//			monthsched.start();
//			Config.setMonthsched(monthsched);
//			
//		} catch (Exception e) {
//			e.printStackTrace();
//		} 

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {


    }


}
